package com.yh.blog.serviceImpl;

import com.yh.blog.config.PersonConfig;
import com.yh.blog.domain.Friend;
import com.yh.blog.mapper.FriendMapper;
import com.yh.blog.service.FriendService;
import com.yh.blog.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FriendServiceImpl  implements FriendService {
    @Resource
    private FriendMapper friendMapper;
    @Autowired
    private PersonConfig personConfig;

    @Override
    public boolean append(Friend friend) {
        return this.friendMapper.insert(friend);
    }

    @Override
    public boolean Remove(Integer friendId) {
        return this.friendMapper.delete(friendId);
    }

    @Override
    public boolean modify(Friend friend) {
        return this.friendMapper.update(friend);
    }

    @Override
    public Friend detail(Integer friendId) {
        return this.friendMapper.selectById(friendId);
    }

    @Override
    public Pager<Friend> list(Integer page) {
        List<Friend> datas=this.friendMapper.selects((page-1)*this.personConfig.getPage_size(), this.personConfig.getPage_size());
        int size=this.friendMapper.size();
        return new Pager<>(datas, size, page, this.personConfig.getPage_size());
    }

    @Override
    public List<Friend> list() {
        return this.friendMapper.selects(0, 0);
    }


}
